package com.community.controller;

import com.community.model.HealthInfo;
import com.community.service.HealthService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet("/ElderHealthOverview")
public class ElderHealthOverviewController extends HttpServlet {
private HealthService  healthService=new HealthService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            List<HealthInfo> allHealthRecords = healthService.getRecentHealthRecords(20);
            request.setAttribute("allHealthRecords", allHealthRecords);
        } catch (Exception e) {
            //将异常的堆栈轨迹打印到标准错误输出流
            e.printStackTrace();
            request.setAttribute("error", "获取健康记录失败: " + e.getMessage());
        }

        request.getRequestDispatcher("/health_view.jsp").forward(request, response);
    }


    }


